package tdh.xt.dao.hibernate;

import org.hibernate.SessionFactory;
import org.hibernate.criterion.DetachedCriteria;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Conditional;
import org.springframework.orm.hibernate4.HibernateTemplate;
import org.springframework.stereotype.Repository;
import tdh.xt.conditional.HibernateCondition;
import tdh.xt.dao.DepartDao;
import tdh.xt.entity.po.Depart;

import java.util.List;

/*
* @Package tdh.xt.dao.hibernate
* @Description Hibernate的实现
* @Author RicarAN
* @Date 2021/6/15 16:18
* @Copyright (c) 2021,南京通达海科技股份有限公司 All Rights Reserved.
* @Version 1.0
* Modification History:
* Date                  Author      Version     Description
* ------------------------------------------------------------------
* 2021/6/15 16:18       RicarAN      1.0        Hibernate部门Dao
*
*/
@Repository("departDao")
@Conditional(HibernateCondition.class)
public class DepartDaoImpl implements DepartDao {

    @Autowired
    HibernateTemplate hibernateTemplate;

    @Autowired
    SessionFactory sessionFactory;

    /*
     * @description 获得所有部门信息
     * @return java.util.List<tdh.xt.entity.po.Depart> 所有部门信息
     * @author RicarAN
     * @version 1.0
     * @date 2021/6/15 16:19
     */
    @Override
    public List<Depart> getAllDepart() {
        return sessionFactory.getCurrentSession()
                .createQuery("from Depart")
                .list();
//        DetachedCriteria criteria = DetachedCriteria.forClass(Depart.class);
//        return (List<Depart>) hibernateTemplate.findByCriteria(criteria);
    }
}
